home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0149_Setting properties of all components.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  1.4 KB  |  38 lines

  1. (*
  2. In article 3A77@popalex1.linknet.net, Bill Taylor <btaylor@popalex1.linknet.net> () writes:
  3. >How can you loop through and set properties of components without
  4. >manually setting each component seperately. For example, I am writing a
  5. >program which uses 16 TPanels and 16 TImages. Currently, I am setting the
  6. >tag and color properties of these components as follows.
  7. >
  8. >Loc1.Tag := 0; Pos1.color := clBlack;
  9. >Loc2.Tag := 0; Pos2.color := clBlack;
  10. >Loc3.Tag := 0; Pos3.color := clBlack;
  11. >Loc4.Tag := 0; Pos4.color := clBlack;
  12. >Loc5.Tag := 0; Pos5.color := clBlack;
  13. >Loc6.Tag := 0; Pos6.color := clBlack;
  14. >Loc7.Tag := 0; Pos7.color := clBlack;
  15. >Loc8.Tag := 0; Pos8.color := clBlack;
  16. >Loc9.Tag := 0; Pos9.color := clBlack;
  17. >Loc10.Tag := 0; Pos10.color := clBlack;
  18. >Loc11.Tag := 0; Pos11.color := clBlack;
  19. >Loc12.Tag := 0; Pos12.color := clBlack;
  20. >Loc13.Tag := 0; Pos13.color := clBlack;
  21. >Loc14.Tag := 0; Pos14.color := clBlack;
  22. >Loc15.Tag := 0; Pos15.color := clBlack;
  23. >Loc16.Tag := 0; Pos16.color := clBlack;
  24. >
  25. >This works, but doesn't look to good. I would like to do a for loop to
  26. >set these properties.
  27. *)
  28.  
  29. Try something of the following flavor:
  30.   for I := 0 to ComponentCount - 1 do
  31.     if (Components[I] is TLabel) or (Components[I] is TImage) then
  32.       with Components[I] as TLabel, Components[I] as TImage do
  33.         begin
  34.         Tag := 0;
  35.         Color := clBlack;
  36.         end;
  37.  
  38.